Fix Print::printf implementation#64
Merged
h2zero merged 1 commit intoh2zero:masterfrom Jan 15, 2025
tsl0922:fix-printf
Merged
Conversation
Owner
|
Thanks! Only concern I have is that it will likely cause a stack overflow for constrained devices, nRF51 and nRF52810 etc.. I will test it and see. |
Contributor
Author
|
The code above maybe better, it uses a smaller buffer first, alloc if the buffer overflow. |
Closed
Contributor
Author
|
Follow up to #68 (comment) I have a working implementation now, if you are OK with the changes, I can open another PR to replace this one @h2zero --- a/builder/frameworks/arduino/nrf5.py
+++ b/builder/frameworks/arduino/nrf5.py
@@ -71,6 +71,8 @@ env.Append(
CPPPATH=[
join(FRAMEWORK_DIR, "cores", board.get("build.core")),
+ join(FRAMEWORK_DIR, "cores", board.get("build.core"),
+ "libc", "printf"),
join(FRAMEWORK_DIR, "cores", board.get("build.core"),
"nordic", "nrfx"),
join(FRAMEWORK_DIR, "cores", board.get("build.core"),--- a/cores/nRF5/Print.cpp
+++ b/cores/nRF5/Print.cpp
@@ -22,6 +22,7 @@
#include <string.h>
#include <math.h>
#include "Arduino.h"
+#include "printf.h"
#include "Print.h"
@@ -187,11 +188,16 @@ size_t Print::println(const Printable& x)
return n;
}
+extern "C" void streamOutput(char character, void* arg)
+{
+ (static_cast<Print *>(arg))->write(character);
+}
+
int Print::printf(const char* format, ...)
{
va_list va;
va_start(va, format);
- int ret = vprintf(format, va);
+ int ret = vfctprintf(&streamOutput, this, format, va);
va_end(va);
return ret;
} |
Owner
|
@tsl0922 That is probably the better solution, please open PR's for this. |
Contributor
Author
Done. This PR has been updated, PR for platform: h2zero/platform-n-able#3. |
h2zero
requested changes
Jan 15, 2025
Owner
h2zero
left a comment
There was a problem hiding this comment.
Looks good, just need to fix a couple things.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement: h2zero/platform-n-able#3.
Fixes #62.